package com.atguigu;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

public class Controller {
	@Resource(name = "accountService")
	IAccountService accountService;
	public Map<String, Object> m = new HashMap<String, Object>();
	
	
	@PostMapping("/add")
	public @ResponseBody Map<String, Object> adddevice(@RequestBody Map<String, String> reqMap) throws Exception {
		String accountname = reqMap.get("username");
		String pwd = reqMap.get("password");
//		Map<String, Object> map = new HashMap<String, Object>();
		boolean b = findByName(accountname);
		if(b == true) {
			m.put("errcode", 1);
			m.put("mess", " �˺�" + accountname + "����");
			return m;
		}
		Account ac = new Account();
		ac.setUsername(accountname);
		try {
			accountService.addAccount(ac);
		} catch (Exception e1) {
			e1.printStackTrace();
			m.put("errcode", 1);
			m.put("mess", "�˺Ŵ���");
			return m;
		}
		m.put("errcode", 0);
		m.put("mess", "success");
		return null;
	}
	
	public Boolean findByName(String name) throws Exception {
		boolean b = accountService.findByName(name);
		return b;
	}
}
